﻿using D.IdentityDbStore.Options;
using Microsoft.Extensions.Hosting;

namespace  D.IdentityDbStore.Tokens
{
    public class TokenCleanupHostService : IHostedService
    {
        private readonly TokenCleanupHelper _tokenCleanup;
        private readonly DbStoreOptions _option;
        public TokenCleanupHostService(TokenCleanupHelper tokenCleanup, DbStoreOptions option)
        {
            _tokenCleanup = tokenCleanup;
            _option = option;
        }

        public Task StartAsync(CancellationToken cancellationToken)
        {
            if (_option.EnableTokenCleanup)
            {
                _tokenCleanup.Start(cancellationToken);
            }
            return Task.CompletedTask;
        }

        public Task StopAsync(CancellationToken cancellationToken)
        {
            if (_option.EnableTokenCleanup)
            {
                _tokenCleanup.Stop();
            }
            return Task.CompletedTask;
        }
    }
}
